package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.vo.ProductSkuBrandVo;
import com.spzx.product.api.domain.vo.SkuDetailVo;
import com.spzx.product.api.domain.vo.SkuSearchVo;
import com.spzx.product.service.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("sku")
public class ProductSkuController extends BaseController {
    @Resource
    private ProductSkuService productSkuService;

    @InnerAuth
    @Operation(summary = "内部调用接口:获取首页热门商品及一级分类列表")
    @GetMapping("/skuOrBrand")
    public R<ProductSkuBrandVo> getSkuOrBrand() {
        ProductSkuBrandVo productSkuBrandVo = productSkuService.getSkuOrBrand();
        return R.ok(productSkuBrandVo);
    }

    @InnerAuth
    @Operation(summary = "内部调用接口:获取商品sku列表")
    @GetMapping("/skuList")
    public R<TableDataInfo> getSkuList(SkuSearchVo skuSearchVo) {
        startPage();
        List<ProductSku> productSkus = productSkuService.getSkuList(skuSearchVo);
        return R.ok(getDataTable(productSkus));
    }

    @InnerAuth
    @Operation(summary = "内部调用接口:获取商品sku详情")
    @GetMapping("/skuDetail/{id}")
    public R<SkuDetailVo> getSkuDetail(@PathVariable Long id) {
        SkuDetailVo skuDetailVo = productSkuService.getSkuDetail(id);
        return R.ok(skuDetailVo);
    }
}
